Skip to content

feat: recover terminal sessions after worker restart - #15

Merged
Coooolfan merged 8 commits into
mainfrom
feat/worker-session-recovery
Aug 8, 2026
Merged

feat: recover terminal sessions after worker restart#15
Coooolfan merged 8 commits into
mainfrom
feat/worker-session-recovery

Conversation

@Coooolfan

Copy link
Copy Markdown
Owner

Summary

Add terminal session recovery so live sessions survive a worker restart. On reconnect the worker reconciles its local state with Console's recovery candidates, restores session leases, and only then starts accepting commands.

Changes

API / Proto

  • Add TerminalSessionRecoveryCandidate/Result/Report/Ack proto messages for the reconciliation handshake

Console

  • Send recovery candidates in ConnectAck; apply the worker's recovery report to refresh leases and drop missing sessions
  • Gate dispatch until recovery completes
  • Mark routes session_unavailable (503) on disconnect instead of clearing them, so bound session IDs return a clean error while the worker is offline or reconciling

worker-docker

  • Use deterministic container names + schema/session-hash labels so containers survive worker exit
  • PreserveOnClose keeps containers running on graceful shutdown
  • On reconnect: restart stopped containers, restore exact leases, remove local orphans Console no longer recognises

worker-bridge-e2b

  • Tag terminal sandboxes with session-id metadata; add E2B List/Connect helpers to rediscover paused sandboxes
  • Reconcile Console recovery candidates on reconnect before accepting commands

worker-boxlite

  • Derive deterministic box names from session-id hashes so boxes survive worker exit
  • Reconcile Console recovery candidates on reconnect before accepting commands

Introduce TerminalSessionRecoveryCandidate/Result/Report/Ack messages
so workers can reconcile terminal sessions with Console after reconnect.
Send recovery candidates in ConnectAck, apply the worker recovery report
to refresh leases and drop missing sessions, and gate dispatch until
recovery completes. Mark routes unavailable instead of clearing them on
disconnect so the bound session_id keeps returning 503 session_unavailable
while the worker is offline or reconciling.
Use deterministic container names and schema/session-hash labels so
terminal containers survive worker exit. On reconnect, reconcile
Console candidates before accepting commands: restart stopped
containers, restore the exact lease, and remove local orphans Console
no longer recognizes. PreserveOnClose keeps containers running on
graceful shutdown.
Tag terminal sandboxes with session-id metadata, add E2B List/Connect
helpers to rediscover paused sandboxes, and reconcile Console recovery
candidates on reconnect before accepting commands. Restarted sandboxes
keep their original session_id and lease.
Derive deterministic box names from session-id hashes so boxes survive
worker exit, and reconcile Console recovery candidates on reconnect
before accepting commands. Restarted boxes keep their original
session_id and lease.
Copilot AI lite review requested due to automatic review settings August 7, 2026 16:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Coooolfan
Coooolfan merged commit ce9eee1 into main Aug 8, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants